#include "tree.h"
#define TREE_SPEED 0.05f;

CTree::CTree() : CMovable()
{

}

CTree::~CTree()
{

}

CTree::CTree(float X, float Y)
{
	reality = 22;
	v_x = 0;
	v_y = -TREE_SPEED;
	pos_x = X;
	width = 16;
	height = 24;
	pos_y = Y+height;
	Top = Y;
	isStopping = 0;
	stopTime = GetTickCount();
}

void CTree::Update(int t)
{
	//int ii = cTree->Del(pos_x,pos_y,width,height);

	float ts = TREE_SPEED;
	pos_y += v_y*t;
	if(pos_y <= Top)
	{
		if(isStopping == 0)
		{
			isStopping = 1;
			stopTime = GetTickCount();
			v_y = 0;
		}
	}
	else if(pos_y >= Top+height)
	{
		if(isStopping == 0)
		{
			isStopping = 1;
			stopTime = GetTickCount();
			v_y = 0;
		}
	}
	if(GetTickCount()-stopTime > 1000 && isStopping == 1)	
		isStopping = 0;
	if(isStopping == 0)
	{
		if (pos_y <= Top)
			v_y = ts;
		else if(pos_y >= Top+height)
			v_y = -ts;
	}
////////////////////////////////////////////////////////////////////////
//	CheckCol();
	//cTree->Add(this,ii);
}

void CTree::RenderFrame(LPDIRECT3DDEVICE9 d3ddv, int t)
{
	DWORD now = GetTickCount();
	Update(t);
	if (now - last_time > 200)
	{
		anim=(anim+1) % 2;
		last_time = now;
	}
	SpriteHandlerEP->Begin(D3DXSPRITE_ALPHABLEND);
	EnemiesPic->Render(_BackBuffer,pos_x,pos_y,width,height,1,13+anim);
	SpriteHandlerEP->End();
}

void CTree::isJumpedOn(CObjects * obj)
{
	if(obj->havingStar == 1)
		Die();
	else
		obj->lvDown();
}

void CTree::Touch(CObjects * obj)
{
	if(obj->havingStar == 1)
		Die();
	else
		obj->lvDown();
}

void CTree::Die()
{
	life = 0;
}